package com.sztx.worker_monitor.web.controller;


import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;





import org.springframework.web.bind.annotation.RequestMethod;

import com.sztx.se.common.domain.Result;
import com.sztx.se.common.domain.ResultCode;
import com.sztx.se.web.controller.BaseController;
import com.sztx.worker_monitor.web.handle.LoginHandle;
import com.sztx.worker_monitor.web.model.PwdInfoModel;

@RequestMapping("/monitor")
@Controller
public class LoginController extends BaseController {
	
	@Autowired(required = false)
	private LoginHandle loginHandle;


	/** *****************************以下为页面控制****************************************/
	@RequestMapping(value="/login", method=RequestMethod.GET)
	public String login(HttpServletRequest request, HttpServletResponse response, Model model) {

		return "monitor/login";
	}
	/*******************************以上为页面控制*****************************************/
	
	
	/******************************以下是操作控制*****************************************/
	@RequestMapping(value="/checkName", method=RequestMethod.POST)
	public Result restartjob(HttpServletRequest request, HttpServletResponse response, Model model) {

		PwdInfoModel pwdInfoModel = new PwdInfoModel();
		String errDes = loginHandle.checkName(pwdInfoModel);
		if(errDes != null){
			Result result = new Result(ResultCode.COMMON_SYSTEM_EXCEPTION, false);
			result.setProperty("errDes", errDes);
			return result;
		}

		Result result = new Result(ResultCode.COMMON_SUCCESS, true);
		result.setProperty("salt", pwdInfoModel.getSalt());
		result.setProperty("disturbance", pwdInfoModel.getDisturbance());
		return result;
	}
	
	
	@RequestMapping(value="/userLogin", method=RequestMethod.POST)
	public Result userLogin(HttpServletRequest request, HttpServletResponse response, Model model) {


		String errDes = loginHandle.userLogin();
		if(errDes != null){
			Result result = new Result(ResultCode.COMMON_SYSTEM_EXCEPTION, false);
			result.setProperty("errDes", errDes);
			return result;
		}

		Result result = new Result(ResultCode.COMMON_SUCCESS, true);
		return result;
	}

	@RequestMapping(value="/logout", method=RequestMethod.POST)
	public Result logout(HttpServletRequest request, HttpServletResponse response, Model model) {

		String errDes = LoginHandle.logout();
		if(errDes != null){
			Result result = new Result(ResultCode.COMMON_SYSTEM_EXCEPTION, false);
			result.setProperty("errDes", errDes);
			return result;
		}

		Result result = new Result(ResultCode.COMMON_SUCCESS, true);
		return result;
	}
	
	
	/******************************以上是操作控制*****************************************/

	
}
